function w = fwhm(x,y)
    if nargin < 2
        y = x;
        x = 1:length(y);
    end
    
    if sum(size(x) ~= size(y))
        error('jcb:fwhm:SizeError','x and y must be of equal size');
    end
    
    if iscell(x)
        w = zeros(1,length(x));
        for ii=1:length(x)
            w(ii) = fwhm(x{ii},y{ii});
        end
    elseif size(x,2) > 1
        w = zeros(1,size(x,2));
        for ii=1:size(x,2)
            w(ii) = fwhm(x(:,ii),y(:,ii));
        end
    else
        [ym p] = max(y);
        ydiff = abs(y-ym/2);
        [~, p1] = min(ydiff(1:p));
        [~, p2] = min(ydiff(p:end));
        p2=p2+p;
        w = abs(x(p1)-x(p2));
    end
end